package com.wp.dao;

import com.wp.domain.Person;
import com.wp.service.PersonService;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class PersonDaoTest {
    ApplicationContext context = new ClassPathXmlApplicationContext("person-spring.xml");
    @Test
    public void findAll() {
        ApplicationContext context = new ClassPathXmlApplicationContext("person-spring.xml");
        PersonService personService = context.getBean("personService",PersonService.class);
        for (Person person : personService.findAll()){
            System.out.println(person);
        }
    }

    @Test
    public void findById() {

        PersonService personService = context.getBean("personService",PersonService.class);

        Person person = personService.findById(1);
        System.out.println(person);
    }

    @Test
    public void add() {
        PersonService personService = context.getBean("personService",PersonService.class);

        int del = personService.del(6);
        System.out.println(del);
    }

    public void del() {
        ApplicationContext context = new ClassPathXmlApplicationContext("person-spring.xml");
        PersonService personService = context.getBean("personService",PersonService.class);
        Person person = new Person();
        person.setName("张三");
        person.setSex("男");
        person.setAge(18);
        person.setRank("三");
        person.setDepartment("三");

        int add = personService.add(person);
        System.out.println(add);
    }

    @Test
    public void upd(){
        ApplicationContext context = new ClassPathXmlApplicationContext("person-spring.xml");
        PersonService personService = context.getBean("personService",PersonService.class);
        Person person = new Person();

        int upd = personService.upd(person);
        System.out.println(upd);
    }
}